<template>
  <div class="todo-header">
    <input type="text" placeholder="输入任务名称，按回车确认"
         v-model:value="title" @keydown.enter="addtodo">
  </div>
</template>

<script>
import {nanoid} from "nanoid";

export default {
  name: "AddItem",
  // props:["add"],
  data(){
    return{
      title:""
    }
  },
  methods:{
    addtodo( ){
      if(this.title.trim().length==0){
        this.title=''
        return
      }
      const obj={id:nanoid(),title:this.title,done:false,isEdit:false}
      console.log(obj)
      this.$emit("add",obj)
      // this.add(obj)
     this.title=''
    }
  }
}
</script>

<style scoped>
input{
  width: 300px;
}
</style>
